package com.chis.mydecode;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @Description 
 * @Company zwx
 * @author wlj
 * @version 2020年02月16日
 */
public class DecodeMain {

    private static String SRCPATH = "F:\\svnc\\代码\\Jm_Project_Trunk07\\Jm_Join_Project\\JmJedis";
    private static String TARPATH = "C:\\Users\\Administrator\\Desktop\\JmJedis";

    public static void main(String[] args) {
        try {
            traverseFolder(SRCPATH);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void traverseFolder(String path) throws Exception{
        File file = new File(path);
        if (file.exists()) {
            File[] files = file.listFiles();
            if (null == files || files.length == 0) {
                return;
            } else {
                for (File file2 : files) {
                    if (file2.isDirectory()) {
                        traverseFolder(file2.getAbsolutePath());
                    } else {
                        if (file2.getAbsolutePath().endsWith(".java")) {
                            System.out.println(file2.getAbsolutePath());
                            String filepath = file2.getAbsolutePath().substring(0,file2.getAbsolutePath().lastIndexOf("\\")).replace(SRCPATH,"");
//                            System.out.println(filepath);
                            String filename = file2.getAbsolutePath().substring((file2.getAbsolutePath().lastIndexOf("\\"))+1);
//                            System.out.println(filename);
                            String tp = TARPATH+filepath;
                            File tf = new File(tp);
                            if(!tf.exists()){
                                tf.mkdirs();
                            }
                            String tff = tp+"\\"+filename.replace(".java",".txt");
                            copyFileUsingFileStreams(file2,new File(tff));

                        }
                    }
                }
            }
        } else {
            System.out.println("文件不存在!");
        }
    }

    private static void copyFileUsingFileStreams(File source, File dest)  throws Exception {
        InputStream input = null;
        OutputStream output = null;
        try {
            input = new FileInputStream(source);
            output = new FileOutputStream(dest);
            byte[] buf = new byte[1024];
            int bytesRead;
            while ((bytesRead = input.read(buf)) > 0) {
                output.write(buf, 0, bytesRead);
            }
        } finally {
            input.close();
            output.close();
        }
    }

}
